home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
EnigmA Amiga Run 1995 October
/
EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso
/
Aminet
/
text
/
tex
/
EVPaths140.lha
/
TeXSaveString.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-05-05
|
3KB
|
163 lines
/*
* TeXSaveString.c - a simple file to show how EVPaths.lib routines work.
*
* This program do not use any startup code.
*
* Copyright © 1994, 1995 by Giuseppe Ghibò
*
* Version 1.1 - 5 May 1995
*
* ----------------------------------------------------------------------
*
* Compile with:
*
* SC OPT LINK LIB EVPaths.lib NOSTKCHK NOSTARTUP TeXSaveString.c
* or
* SC OPT NOSTKCHK TeXSaveString.c
* SLINK FROM TeXSaveString.o TO TeXSaveString LIB EVPaths.lib LIB:sc.lib
* or
* SC OPT NOSTKCHK NOSTARTUP LINK TeXSaveString.c EVPaths.c SNPrintf.a
*
*
* Usage:
*
* TeXSaveString VAR=MYVAR FILE=<filename> [SHOW] STRING=<string>
*
* For example, with:
*
* SetEnv NAME=GOOFY STRING=ram:,T:
* TeXSaveString VAR=GOOFY FILE=one.txt STRING=example
*
* you'll obtain:
*
* Written string `example' in the file: `one.txt
*
* Then type:
*
* Protect ram:one.txt -d
*
* and again:
*
* TeXSaveString VAR=GOOFY FILE=one.txt STRING=example SHOW
*
* then you'll obtain:
*
* Written string `example' in the file: `T:one.txt'
*
*/
#include <exec/execbase.h>
#include <workbench/startup.h>
#include <string.h>
#include <proto/dos.h>
#include <proto/exec.h>
#include "evpaths.h"
#define TEMPLATE "VAR/K,FILE/A,SHOW/S,STRING/F"
enum { OPT_VAR,
OPT_FILE,
OPT_SHOW,
OPT_STRING,
OPT_COUNT };
extern struct ExecBase *SysBase;
extern struct DosLibrary *DOSBase;
#define BUFLEN 256
#define EVPBUF 8192L
void __saveds Main(void) {
struct Process *me;
struct WBStartup *WBenchMsg;
struct RDArgs *rdargs;
LONG opts[OPT_COUNT];
char buf[BUFLEN];
STRPTR varname = "", fname = NULL, String;
BOOL show = 0;
struct EnvVarPath *var;
BPTR fh;
SysBase = *(struct ExecBase **)4;
if ((DOSBase = (struct DosLibrary *)OpenLibrary("dos.library", 36L)) == NULL)
return;
me = (struct Process *)SysBase->ThisTask;
if (me->pr_CLI)
{
WBenchMsg = NULL;
memset (opts, 0, sizeof(opts));
if (rdargs = ReadArgs(TEMPLATE, opts, NULL))
{
if (opts[OPT_VAR])
varname = (STRPTR) opts[OPT_VAR];
if (opts[OPT_FILE])
fname = (STRPTR) opts[OPT_FILE];
if (opts[OPT_STRING])
String = (STRPTR) opts[OPT_STRING];
if (opts[OPT_SHOW])
show = 1;
var = Alloc_EnvVarPath(varname, EVPBUF);
Init_EnvVarPath(var, ".", ENVPATH_DEFSTR);
if (show)
{
int i = 0;
Printf("The environment variable `%s' has length %ld\n", varname, GetVarLength(varname));
while (var->storage.strings[i])
Printf("%ld -> `%s'\n", i, var->storage.strings[i++]);
}
if ((fh = EVP_Open(fname, var, buf, BUFLEN, MODE_NEWFILE)) != DOSFALSE)
{
Write(fh, String, strlen(String));
Close(fh);
Printf("Written string `%s' in the file: `%s'\n",String,buf);
}
else
Printf("Can't write in the file `%s'.\n",fname);
Free_EnvVarPath(var);
FreeArgs(rdargs);
}
else
PrintFault(IoErr(), NULL);
}
else
{
BPTR StdOut;
WaitPort(&me->pr_MsgPort);
WBenchMsg = (struct WBStartup *)GetMsg(&me->pr_MsgPort);
if (StdOut = Open("CON:20/20/400/80/A Window/Auto/Close/Wait", MODE_NEWFILE))
{
FPrintf(StdOut,"You must run me from CLI, not from WB!\n");
Close(StdOut);
}
}
if (DOSBase)
CloseLibrary((struct Library *)DOSBase);
if (WBenchMsg)
{
Forbid();
ReplyMsg(&WBenchMsg->sm_Message);
}
}